<template>
  <div id="bg">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item>系统管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户操作日志</el-breadcrumb-item>
    </el-breadcrumb>
    <div id="tab">
      <!-- 搜索栏 -->
      <div>
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item label="账号">
            <el-input v-model="formInline.account" placeholder=""></el-input>
          </el-form-item>
          <el-form-item label="操作用户">
            <el-input v-model="formInline.user" placeholder=""></el-input>
          </el-form-item>
          <el-form-item label="操作时间段">
            <el-date-picker v-model="value" unlink-panels type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
          <el-button type="primary" @click="onSearch">查询</el-button>
          <el-button type="info" @click="onReset">重置</el-button>
        </el-form>
      </div>
      <el-divider></el-divider>
      <!-- 数据表格 -->
      <div id="table">
        <el-table :data="tablesData" stripe style="width: 100%">
          <el-table-column prop="l_id" label="序号" width="160">
          </el-table-column>
          <el-table-column prop="account" label="账号" width="180">
          </el-table-column>
          <el-table-column prop="name" label="操作用户" width="240">
          </el-table-column>
          <el-table-column prop="l_text" label="操作描述" width="200">
          </el-table-column>
          <el-table-column prop="l_caozuo" label="操作时间" width="260">
          </el-table-column>
          <el-table-column prop="operate" label="操作">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="handleDetail(scope.row)">查看详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <div id="pages">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page" :page-sizes="[5, 10, 15, 20]" :page-size="5" layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
      </div>
    </div>
    <!-- 查看详情按钮 -->
    <el-dialog title="用户详情" :visible.sync="dialogTableVisible">
      <el-table :data="gridData">
        <el-table-column label="头像" width="150">
          <template slot-scope="scope">
            <img :src="require('../assets/images/'+scope.row.figure+'.jpg') " alt="" width="120px" height="120px" />
          </template>
        </el-table-column>
        <el-table-column property="work_id" label="工号" width="150"></el-table-column>
        <el-table-column property="name" label="姓名" width="150"></el-table-column>
        <el-table-column property="sex" label="性别" width="150"></el-table-column>
        <el-table-column property="type" label="类型" width="150"></el-table-column>
        <el-table-column property="post_name" label="岗位" width="150"></el-table-column>
        <el-table-column property="department_name" label="所属部门" width="150"></el-table-column>
        <el-table-column property="post_time" label="入职时间" width="150"></el-table-column>
        <el-table-column property="phone" label="手机号码" width="150"></el-table-column>
        <el-table-column property="idcard" label="身份证号" width="150"></el-table-column>
        <el-table-column property="address" label="居住地址"></el-table-column>
        <el-table-column property="email" label="邮箱" width="150"></el-table-column>
        <el-table-column property="l_text" label="操作描述" width="150"></el-table-column>
        <el-table-column property="l_caozuo" label="操作时间" width="150"></el-table-column>
        <el-table-column property="l_ip" label="IP地址" width="150"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data: function () {
    return {
      dialogTableVisible: false,
      formInline: {
        account: '',
        user: '',
        value: ''
      },
      tableData: [],
      gridData: [],
      page: 1,
      pageSize: 5,
      total: 0,
      value: '',
    }
  },
  methods: {
    onSearch() {
      this.page = 1;
      this.$axios({
        url: '/system/systemoperate/get',
        params: {
          account: this.formInline.account,
          user: this.formInline.user,
          time: this.value
        }
      }).then((res) => {
        console.log(res);
        this.tableData = res.data.data
        this.total = res.data.total;
      })
    },
    onReset() {
      this.page = 1;
      this.getData();
      this.formInline.account = '';
      this.formInline.user = '';
      this.value = '';
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.onSearch();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.page = val;
    },
    handleDetail(item) {
      this.dialogTableVisible = true;
      // console.log(item.l_id);
      this.$axios({
        url: '/system/systemoperate/detail',
        params: { l_id: item.l_id }
      }).then((res) => {
        console.log(res);
        this.gridData = res.data.data
      })
    },
    getData() {
      this.$axios({
        url: '/system/systemoperate/get',
        params: {
          account: '',
          user: '',
          time: ''
        }
      }).then((res) => {
        this.tableData = res.data.data
        this.total = res.data.total;
      })
    }
  },
  created: function () {
    this.getData();
  },
  computed: {
    tablesData() {
      return this.tableData.slice((this.page - 1) * this.pageSize, this.page * this.pageSize)
    }
  }
}
</script>
<style scoped>
.el-row span {
  cursor: pointer;
}
.el-main,
#bg {
  height: 100%;
}
.el-breadcrumb {
  margin: 20px;
}
#closeBtn {
  text-align: right;
}
#bg {
  background-color: rgb(242, 242, 242);
}
#tab {
  padding: 30px;
  background-color: #fff;
  margin: 0 20px;
}
.el-breadcrumb {
  margin-top: 0;
  padding-top: 20px;
}
#pages {
  margin-top: 20px;
  text-align: right;
}
</style>
